package com.daoyin.ssph.frontAction;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.daoyin.ssph.bean.Translation;
import com.daoyin.ssph.service.TranslationService;
import com.daoyin.ssph.tools.MyPagination;
import com.daoyin.ssph.tools.MyPaginations;

public class TranslationAction {
	private TranslationService ta;

	
	public void setTa(TranslationService ta) {
		this.ta = ta;
	}
	private String id;
	
	public void setId(String id) {
		this.id = id;
	}

	public String show(){
		HttpServletRequest request = ServletActionContext.getRequest();

		List<Translation> list = ta.query();
		
		for(int i = 0; i < list.size(); i++){
			if(list.get(i).getPublish() == 0){
				list.remove(i);
			}
		}
		
		String str=(String)request.getParameter("Page");
		int p=1;
		MyPaginations pagination = new MyPaginations();
		list=pagination .getInitPage(list,1,9);
		p=pagination.getPage(str);
		list=(ArrayList)pagination.getAppointPage(p);
		String pages = pagination.printCtrl(p);
		request.setAttribute("pages", pages);
		request.setAttribute("show", list);
		return "success";
	
	}
	public String showDetails(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Translation translation = ta.query(Integer.parseInt(id));
		request.setAttribute("trans", translation);
		return "success";
	}
	
}
